﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using danreng.Application;
using sharp_net;
using sharp_net.Mvc;
using Microsoft.Practices.Unity;
using System.Web.Http.Dispatcher;

namespace danreng.Host {

    public class MvcApplication : System.Web.HttpApplication {
        protected void Application_Start() {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            BaseApplication.Initialize();

            IocLocator.Container.RegisterType<ILibraryService, LibraryApplication>(new HttpContextLife<ILibraryService>());
            IocLocator.Container.RegisterType<IUserService, UserApplication>(new HttpContextLife<IUserService>());
            IocLocator.Container.RegisterType<IItemService, ItemApplication>(new HttpContextLife<IItemService>());
            IocLocator.Container.RegisterType<IShopService, ShopApplication>(new HttpContextLife<IShopService>());
            IocLocator.Container.RegisterType<IFormsAuthentication, FormsAuthenticationWithAuths>(new ContainerControlledLifetimeManager());

            DependencyResolver.SetResolver(IocLocator.Instance);

            //Deploy
            UrlBuild.ControlDeploy = eControlDeploy.NoDeploy;
            UrlBuild.Stamp = "121127";
        }

        public override void Init() {
            this.PostAuthenticateRequest += SecurityExtensions.PostAuthenticateRequestHandler;
            base.Init();
        }
    }
}